package com.group02.community.controller;


import com.group02.community.entity.dict.SysDictType;
import com.group02.community.mapper.DictTypeMapper;
import com.group02.community.service.IDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@CrossOrigin
@RestController
@RequestMapping("dict")
public class DictController {
    @Autowired
    IDictTypeService dictTypeService;

    @GetMapping("maps/{type}")
    public ResponseEntity<Map<String, SysDictType>> getMap(@PathVariable String type){
        Map<String, SysDictType> map = new HashMap<String, SysDictType>();
        String[] dictType = type.split(",");
        for (int i = 0; i < dictType.length; i++) {
            SysDictType sysDictType = dictTypeService.getDictType(dictType[i]);
            map.put(dictType[i],sysDictType);
        }
        return ResponseEntity.ok(map);
    }
}
